home *** CD-ROM | disk | FTP | other *** search
- #include "FontMancer.h"
- #include "FontDisplay.h"
- #include "About.h"
- #include "Prefs.h"
- #include "Display.h"
- #include "Standard.h"
- #include "StandardMenu.h"
- #include "StandardEvent.h"
- #include "AEHandler.h"
-
-
-
- Boolean gQuit;
- Boolean gInBackground;
- Boolean gDManager;
- Boolean gSManager;
- WindowPtr gMainWindow;
- long gLastKeyTime;
- Str255 gSamplePhrase;
- Str255 gListNavString;
-
- main()
- {
- MaxApplZone();
- InitToolbox();
- InitAEAccept();
- InitMenuBar();
- InitMainWindow();
- CreateFontList();
- MainEventLoop();
- UpdatePrefs();
- DisposeMainWindow();
- return(0);
- }
-
- void InitToolbox()
- {
- long response;
- OSErr error;
-
- gInBackground = gQuit = gDManager = gSManager = FALSE;
- gListNavString[0] = 0;
- gLastKeyTime = 0;
-
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- TEInit();
- InitDialogs(0L);
- InitCursor();
- if (Gestalt(gestaltSystemVersion,&response) || response < 0x700)
- DeathAlert(errWimpySystem,NIL);
- error = Gestalt(gestaltDisplayMgrVers,&response);
- if (!error && response >= 0x00020000)
- gDManager = TRUE;
- error = Gestalt(gestaltSoundAttr,&response);
- if (!error && (response & gestalt16BitAudioSupport))
- gSManager = TRUE;
- }
-
- void InitMainWindow()
- {
- short loop,error;
- struct picStorage *buttonPic;
- FMStuff *FMStore;
- ControlHandle itemHandle;
- struct prefStuff Prefs;
-
- FMStore = (FMStuff *) NewPtr(sizeof(FMStuff));
- gMainWindow = GetNewCWindow(rMainWindow,NIL,(WindowPtr) -1);
- SetPort(gMainWindow);
- TextFont(systemFont);
- SetWRefCon(gMainWindow,(long) FMStore);
- for (loop=iPlainButton; loop <= iShadowButton; loop++) {
- buttonPic = (struct picStorage *) NewPtr(sizeof(struct picStorage));
- buttonPic->buttonHilite = 0;
- buttonPic->buttonNormal = GetPicture(129 + loop);
- buttonPic->buttonPressed = GetPicture(135 + loop);
- buttonPic->buttonInactUp = GetPicture(141 + loop);
- buttonPic->buttonInactDown = GetPicture(147 + loop);
- itemHandle = GetNewControl(128 + loop,gMainWindow);
- SetCRefCon(itemHandle,(long) buttonPic);
- FMStore->ctlHandles[loop] = itemHandle;
- }
- FMStore->ctlHandles[iSizePopUp] = GetNewControl(134,gMainWindow);
- SetControlValue(FMStore->ctlHandles[iSizePopUp],3);
- SetRect(&(FMStore->itemRects[iButtonRect]),10,4,311,36);
- SetRect(&(FMStore->itemRects[iLineRect]),4,40,317,41);
- SetRect(&(FMStore->itemRects[iTextRect1]),10,45,311,61);
- SetRect(&(FMStore->itemRects[iListRect]),10,66,311,162);
- SetRect(&(FMStore->itemRects[iTextRect2]),10,166,311,182);
- SetRect(&(FMStore->itemRects[iMenuNameRect]),215,9,250,25);
- SetRect(&(FMStore->itemRects[iSampleRect]),10,187,311,290);
- error = LoadPrefs(&Prefs);
- if (!error)
- ConfigAppWithPrefs(Prefs,*FMStore);
- if (gDManager)
- CheckWindowPrefs();
- ShowWindow(gMainWindow);
- }
-
- void CheckWindowPrefs()
- {
- GDHandle gDevice;
- GrafPtr oldPort;
-
- GetPort(&oldPort);
- gDevice = DMGetFirstScreenDevice(dmAllDisplays);
- HLock((Handle) gDevice);
- HandleDeviceChange(gDevice,&((**gDevice).gdRect));
- HUnlock((Handle) gDevice);
- gDevice = DMGetNextScreenDevice(gDevice,dmAllDisplays);
- while (gDevice != NIL) {
- HLock((Handle) gDevice);
- HandleDeviceChange(gDevice,&((**gDevice).gdRect));
- HUnlock((Handle) gDevice);
- gDevice = DMGetNextScreenDevice(gDevice,dmAllDisplays);
- }
- SetPort(oldPort);
- }
-
- void ConfigAppWithPrefs(struct prefStuff Prefs, FMStuff FMStore)
- {
- BlockMove(Prefs.samplePhrase,gSamplePhrase,Prefs.samplePhrase[0] + 1);
- MoveWindow(gMainWindow,Prefs.windowPosition.h,Prefs.windowPosition.v,FALSE);
- if (gSamplePhrase[0] > 255)
- gSamplePhrase[0] = 255;
- }
-
- void UpdatePrefs()
- {
- struct prefStuff Prefs;
- WindowPeek windowInfo;
- RgnHandle windowRgn;
-
- windowInfo = (WindowPeek) gMainWindow;
- windowRgn = windowInfo->contRgn;
- HLock((Handle) windowRgn);
- BlockMove(gSamplePhrase,Prefs.samplePhrase,gSamplePhrase[0] + 1);
- SetPt(&(Prefs.windowPosition),(**windowRgn).rgnBBox.left,(**windowRgn).rgnBBox.top);
- SavePrefs(&Prefs);
- HUnlock((Handle) windowRgn);
- }
-
- void DisposeMainWindow()
- {
- short loop;
- struct picStorage *buttonPic;
- FMStuff *FMStore;
-
- FMStore = (FMStuff *) GetWRefCon(gMainWindow);
- for (loop=iShadowButton; loop >= iPlainButton; loop--) {
- buttonPic = (struct picStorage *) GetCRefCon(FMStore->ctlHandles[loop]);
- ReleaseResource((Handle) buttonPic->buttonInactDown);
- ReleaseResource((Handle) buttonPic->buttonInactUp);
- ReleaseResource((Handle) buttonPic->buttonPressed);
- ReleaseResource((Handle) buttonPic->buttonNormal);
- DisposeControl(FMStore->ctlHandles[loop]);
- }
- LDispose(FMStore->fontList);
- DisposePtr((Ptr) FMStore);
- DisposeWindow(gMainWindow);
- }
-
- void InitMenuBar()
- {
- Handle menuBar;
-
- menuBar = GetNewMBar(rMenuBar);
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(mApple),'DRVR');
- DrawMenuBar();
- }
-
- void MainEventLoop()
- {
- RgnHandle cursorRgn;
- Boolean gotEvent;
- EventRecord event;
-
-
- cursorRgn = NIL;
- while (!gQuit) {
- gotEvent = WaitNextEvent(everyEvent, &event, MAXLONG, cursorRgn);
- if (gotEvent) HandleEvent(&event);
- }
- }
-
- void InfoAlert(short infoNumber, Str255 infoMessage)
- {
- short itemHit;
- Str255 theMessage;
-
- SetCursor(&qd.arrow);
- GetIndString(theMessage,rInfoStrings,infoNumber);
- ParamText(theMessage,infoMessage,NIL,NIL);
- itemHit = Alert(rInfoAlert,NIL);
- }
-
- void DeathAlert(short errNumber, Str255 errorInfo)
- {
- short itemHit;
- Str255 theMessage;
-
- SetCursor(&qd.arrow);
- GetIndString(theMessage,rErrorStrings,errNumber);
- ParamText(theMessage,errorInfo,NIL,NIL);
- itemHit = Alert(rErrorAlert,NIL);
- ExitToShell();
- }